package com.example.zou0614.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zou0614.mapper.StudnetMapper;
import com.example.zou0614.pojo.StScore;
import com.example.zou0614.pojo.Student;
import com.example.zou0614.service.StudentService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class StudentServiceImpl  extends ServiceImpl<StudnetMapper, Student> implements StudentService {
    @Autowired
    private StudnetMapper studnetMappper;

    @Override
    public IPage<Student> getStudentPage(Student student) {

                MPJLambdaWrapper<Student> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(Student.class).selectAll(StScore.class).leftJoin(StScore.class,StScore::getId,Student::getScoreid);
        if (student.getAsdf() != null) {
            wrapper.eq(StScore::getAsdf, student.getAsdf());
        }else{
            wrapper.eq(StScore::getAsdf,1);
        }




        IPage<Student> studentIPage = studnetMappper.selectJoinPage(new Page<Student>(student.getPage(), student.getLimit()), Student.class, wrapper);
        return studentIPage;
    }
//    @Override
//    public IPage<Student> getStudentPage(Student student) {
//
//        MPJLambdaWrapper<Student> wrapper = new MPJLambdaWrapper<>();
//        wrapper.selectAll(Student.class).selectAll(StScore.class).leftJoin(StScore.class,StScore::getId,Student::getScoreid);
//        if (student.getName() != null) {
//            wrapper.like(Student::getName, student.getName());
//        }
//        if (student.getEntrydate() != null){
//            wrapper.eq(Student::getEntrydate,student.getEntrydate());
//        }else{
//            Date date = Date.valueOf("2024-06-01");
//            wrapper.eq(Student::getEntrydate,date);
//        }
//
//        IPage<Student> studentIPage = studnetMappper.selectJoinPage(new Page<Student>(student.getPage(), student.getLimit()), Student.class, wrapper);
//        return studentIPage;
//    }
}
